<?php 
defined('IN_TS') or die('Access Denied.');

switch($ts){
	
	 case "list":
	 	$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
		$url = SITE_URL.'index.php?app=vote&ac=admin&mg=vote&ts=list&page=';
		$lstart = $page*10-10;
		$newsNum = $new['vote']->findCount('vote');
		$pageUrl = pagination($newsNum, 10, $page, $url);
	 $arrVote = $new['vote']->findAll('vote',null,'voteid desc',null, $lstart.',10');
	 
	 foreach($arrVote as $key=>$item){
		$arrVote[$key]['content'] = tsDecode($item['content']);
	 }
	 
	 include template("admin/vote_list");
	 break;
	
	//审核
	case "check":
		$id = intval($_GET['id']);
		$page = intval($_GET['page']);
		$new['vote']->update('vote',array(
				'voteid'=>$id,
		),array(
				'ischeck'=>1,
		));
		header("Location: ".SITE_URL.'index.php?app=vote&ac=admin&mg=vote&ts=list&page='.$page);
		break;
	//取消审核
	case "uncheck":
		$id = intval($_GET['id']);
		$page = intval($_GET['page']);
		$new['vote']->update('vote',array(
				'voteid'=>$id,
		),array(
				'ischeck'=>0,
		));
		header("Location: ".SITE_URL.'index.php?app=vote&ac=admin&mg=vote&ts=list&page='.$page);
		break;
		
	case "delete":
	
	$id = intval($_GET['id']);
	$page = intval($_GET['page']);
	$new['vote']->delete('vote',array(
			'voteid'=>$id,
	));
	$new['vote']->delete('vote_option',array(
			'voteid'=>$id,
	));
	$new['vote']->delete('vote_select',array(
			'voteid'=>$id,
	));
	$new['vote']->delete('vote_comment',array(
			'voteid'=>$id,
	));
	header("Location: ".SITE_URL.'index.php?app=vote&ac=admin&mg=vote&ts=list&page='.$page);
	break;
	
	case "clean":
		
		$arrVote = $new['vote']->findAll('vote',"`voteid`='47'");
		
		foreach($arrVote as $key=>$item){
			$new['vote']->delete('vote_comment',array('voteid'=>$item['voteid']));
			$new['vote']->delete('vote_option',array('voteid'=>$item['voteid']));
			$new['vote']->delete('vote_select',array('voteid'=>$item['voteid']));
			aac('user')->toEmpty($item['userid']);
			$new['vote']->delete('vote',array('voteid'=>$item['voteid']));
		}
		
		echo 'OK';
		
		break;
	
}


